package com.dckj.auto.controller;



import com.dckj.auto.common.utils.JsonUtils;
import com.dckj.auto.common.utils.StringUtil;
import com.dckj.auto.common.utils.qiniu.QiNiuUpLode;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import java.io.IOException;

/**
 * @since 1.0
 * ${tags}
 * <br><b>作者： @author WangDong</b>
 * <br>创建时间：2018/2/22 0022 18:37
 */

@RestController
@RequestMapping("/upLode/")
public class QiNiuController {

    @RequestMapping(value = "qiNiu/delete",method = RequestMethod.POST)
    @ResponseBody
    public Object deleteFile(String filePath){
        boolean delete = QiNiuUpLode.delete(StringUtil.oldUrl(filePath));
        if (delete){
            return JsonUtils.success("删除文件成功！");
        }
        return JsonUtils.error("删除文件失败！");
    }


    @RequestMapping(value = "qiNiu/images/save",method = RequestMethod.POST)
    @ResponseBody
    public Object uploadImgToQiNiu(@RequestParam("images") MultipartFile[] images) throws IOException {
        Object o = QiNiuUpLode.uploadFileToQiNiu(images);
        return o;
    }


    @RequestMapping(value = "qiNiu/file/save",method = RequestMethod.POST)
    @ResponseBody
    public Object uploadFileToQiNiu(@RequestParam("file") MultipartFile[] file) throws IOException {
        return QiNiuUpLode.uploadFileToQiNiu(file);
    }

    @RequestMapping(value = "local/images/save",method = RequestMethod.POST)
    @ResponseBody
    public Object insertImg(@RequestParam("images") MultipartFile[] images, HttpServletRequest request) throws IOException {
        return QiNiuUpLode.uploadFile(images,request);
    }


    @RequestMapping(value = "local/file/save",method = RequestMethod.POST)
    @ResponseBody
    public Object insertFile(@RequestParam("file") MultipartFile[] file, HttpServletRequest request) throws IOException {
        return QiNiuUpLode.uploadFile(file,request);
    }

    @RequestMapping(value = "qiNiu/token",method = RequestMethod.POST)
    @ResponseBody
    public Object getToken(){
        return JsonUtils.success("七牛Token",QiNiuUpLode.getToken());
    }

}
